if index is equal to the line length, then position iterator before
authorHavoc Pennington <hp@redhat.com>
Thu, 4 Jan 2001 20:01:32 +0000 (20:01 +0000)
committerHavoc Pennington <hp@src.gnome.org>
Thu, 4 Jan 2001 20:01:32 +0000 (20:01 +0000)
2001-01-04  Havoc Pennington  <hp@redhat.com>

* gtk/gtktextlayout.c (line_display_index_to_iter): if index is
equal to the line length, then position iterator before paragraph
separators. Fixes crash reported by Mikael Hermansson when
pressing left arrow from the start of a line.

* gtk/gtktextiter.c (iter_set_from_byte_offset): Add g_error
about byte indexes off the end
(iter_set_from_char_offset): add g_error about char offsets
off the end

ChangeLog
ChangeLog.pre-2-0
ChangeLog.pre-2-10
ChangeLog.pre-2-2
ChangeLog.pre-2-4
ChangeLog.pre-2-6
ChangeLog.pre-2-8
gtk/gtktextiter.c
gtk/gtktextlayout.c

index 605f1dd4f338b000da8cec80cb070b9f1c59cc1a..be4b5b272422a0f3db5792ebd64f9c6b59a52511 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2001-01-04  Havoc Pennington  <hp@redhat.com>
+
+       * gtk/gtktextlayout.c (line_display_index_to_iter): if index is
+       equal to the line length, then position iterator before paragraph 
+       separators. Fixes crash reported by Mikael Hermansson when
+       pressing left arrow from the start of a line.   
+
+       * gtk/gtktextiter.c (iter_set_from_byte_offset): Add g_error
+       about byte indexes off the end
+       (iter_set_from_char_offset): add g_error about char offsets
+       off the end
+
 2001-01-03  Havoc Pennington  <hp@redhat.com>
 
        * gtk/gtktextbtree.c: Adapt to uscore-ification of gtktextiterprivate
index 605f1dd4f338b000da8cec80cb070b9f1c59cc1a..be4b5b272422a0f3db5792ebd64f9c6b59a52511 100644 (file)
@@ -1,3 +1,15 @@
+2001-01-04  Havoc Pennington  <hp@redhat.com>
+
+       * gtk/gtktextlayout.c (line_display_index_to_iter): if index is
+       equal to the line length, then position iterator before paragraph 
+       separators. Fixes crash reported by Mikael Hermansson when
+       pressing left arrow from the start of a line.   
+
+       * gtk/gtktextiter.c (iter_set_from_byte_offset): Add g_error
+       about byte indexes off the end
+       (iter_set_from_char_offset): add g_error about char offsets
+       off the end
+
 2001-01-03  Havoc Pennington  <hp@redhat.com>
 
        * gtk/gtktextbtree.c: Adapt to uscore-ification of gtktextiterprivate
index 605f1dd4f338b000da8cec80cb070b9f1c59cc1a..be4b5b272422a0f3db5792ebd64f9c6b59a52511 100644 (file)
@@ -1,3 +1,15 @@
+2001-01-04  Havoc Pennington  <hp@redhat.com>
+
+       * gtk/gtktextlayout.c (line_display_index_to_iter): if index is
+       equal to the line length, then position iterator before paragraph 
+       separators. Fixes crash reported by Mikael Hermansson when
+       pressing left arrow from the start of a line.   
+
+       * gtk/gtktextiter.c (iter_set_from_byte_offset): Add g_error
+       about byte indexes off the end
+       (iter_set_from_char_offset): add g_error about char offsets
+       off the end
+
 2001-01-03  Havoc Pennington  <hp@redhat.com>
 
        * gtk/gtktextbtree.c: Adapt to uscore-ification of gtktextiterprivate
index 605f1dd4f338b000da8cec80cb070b9f1c59cc1a..be4b5b272422a0f3db5792ebd64f9c6b59a52511 100644 (file)
@@ -1,3 +1,15 @@
+2001-01-04  Havoc Pennington  <hp@redhat.com>
+
+       * gtk/gtktextlayout.c (line_display_index_to_iter): if index is
+       equal to the line length, then position iterator before paragraph 
+       separators. Fixes crash reported by Mikael Hermansson when
+       pressing left arrow from the start of a line.   
+
+       * gtk/gtktextiter.c (iter_set_from_byte_offset): Add g_error
+       about byte indexes off the end
+       (iter_set_from_char_offset): add g_error about char offsets
+       off the end
+
 2001-01-03  Havoc Pennington  <hp@redhat.com>
 
        * gtk/gtktextbtree.c: Adapt to uscore-ification of gtktextiterprivate
index 605f1dd4f338b000da8cec80cb070b9f1c59cc1a..be4b5b272422a0f3db5792ebd64f9c6b59a52511 100644 (file)
@@ -1,3 +1,15 @@
+2001-01-04  Havoc Pennington  <hp@redhat.com>
+
+       * gtk/gtktextlayout.c (line_display_index_to_iter): if index is
+       equal to the line length, then position iterator before paragraph 
+       separators. Fixes crash reported by Mikael Hermansson when
+       pressing left arrow from the start of a line.   
+
+       * gtk/gtktextiter.c (iter_set_from_byte_offset): Add g_error
+       about byte indexes off the end
+       (iter_set_from_char_offset): add g_error about char offsets
+       off the end
+
 2001-01-03  Havoc Pennington  <hp@redhat.com>
 
        * gtk/gtktextbtree.c: Adapt to uscore-ification of gtktextiterprivate
index 605f1dd4f338b000da8cec80cb070b9f1c59cc1a..be4b5b272422a0f3db5792ebd64f9c6b59a52511 100644 (file)
@@ -1,3 +1,15 @@
+2001-01-04  Havoc Pennington  <hp@redhat.com>
+
+       * gtk/gtktextlayout.c (line_display_index_to_iter): if index is
+       equal to the line length, then position iterator before paragraph 
+       separators. Fixes crash reported by Mikael Hermansson when
+       pressing left arrow from the start of a line.   
+
+       * gtk/gtktextiter.c (iter_set_from_byte_offset): Add g_error
+       about byte indexes off the end
+       (iter_set_from_char_offset): add g_error about char offsets
+       off the end
+
 2001-01-03  Havoc Pennington  <hp@redhat.com>
 
        * gtk/gtktextbtree.c: Adapt to uscore-ification of gtktextiterprivate
index 605f1dd4f338b000da8cec80cb070b9f1c59cc1a..be4b5b272422a0f3db5792ebd64f9c6b59a52511 100644 (file)
@@ -1,3 +1,15 @@
+2001-01-04  Havoc Pennington  <hp@redhat.com>
+
+       * gtk/gtktextlayout.c (line_display_index_to_iter): if index is
+       equal to the line length, then position iterator before paragraph 
+       separators. Fixes crash reported by Mikael Hermansson when
+       pressing left arrow from the start of a line.   
+
+       * gtk/gtktextiter.c (iter_set_from_byte_offset): Add g_error
+       about byte indexes off the end
+       (iter_set_from_char_offset): add g_error about char offsets
+       off the end
+
 2001-01-03  Havoc Pennington  <hp@redhat.com>
 
        * gtk/gtktextbtree.c: Adapt to uscore-ification of gtktextiterprivate
index e2e0f44cf9d93bb7d7b783a0a7d6c26e9916abb4..c085fb32663545a1b6c1231b2b15bdb75fa92424 100644 (file)
@@ -92,12 +92,14 @@ iter_set_from_byte_offset (GtkTextRealIter *iter,
 {
   iter_set_common (iter, line);
 
-  _gtk_text_line_byte_locate (iter->line,
-                              byte_offset,
-                              &iter->segment,
-                              &iter->any_segment,
-                              &iter->segment_byte_offset,
-                              &iter->line_byte_offset);
+  if (!_gtk_text_line_byte_locate (iter->line,
+                                   byte_offset,
+                                   &iter->segment,
+                                   &iter->any_segment,
+                                   &iter->segment_byte_offset,
+                                   &iter->line_byte_offset))
+    g_error ("Byte index %d is off the end of the line",
+             byte_offset);
 }
 
 static void
@@ -107,12 +109,14 @@ iter_set_from_char_offset (GtkTextRealIter *iter,
 {
   iter_set_common (iter, line);
 
-  _gtk_text_line_char_locate (iter->line,
-                              char_offset,
-                              &iter->segment,
-                              &iter->any_segment,
-                              &iter->segment_char_offset,
-                              &iter->line_char_offset);
+  if (!_gtk_text_line_char_locate (iter->line,
+                                   char_offset,
+                                   &iter->segment,
+                                   &iter->any_segment,
+                                   &iter->segment_char_offset,
+                                   &iter->line_char_offset))
+    g_error ("Char offset %d is off the end of the line",
+             char_offset);
 }
 
 static void
index 458142dec55689a5ca51777bb1f4b71f79a80a0f..035d4935a8cc9aaf6c12856336b37c0b42d17bf7 100644 (file)
@@ -1929,6 +1929,8 @@ line_display_index_to_iter (GtkTextLayout      *layout,
                            gint                index,
                            gint                trailing)
 {
+  gint line_len;
+  
   if (index >= display->insert_index + layout->preedit_len)
     index -= layout->preedit_len;
   else if (index > display->insert_index)
@@ -1937,8 +1939,25 @@ line_display_index_to_iter (GtkTextLayout      *layout,
       trailing = 0;
     }
   
-  _gtk_text_btree_get_iter_at_line (_gtk_text_buffer_get_btree (layout->buffer),
-                                   iter, display->line, index);
+  line_len = _gtk_text_line_byte_count (display->line);
+  g_assert (index <= line_len);
+
+  if (index < line_len)
+    _gtk_text_btree_get_iter_at_line (_gtk_text_buffer_get_btree (layout->buffer),
+                                      iter, display->line, index);
+  else
+    {
+      /* Clamp to end of line - really this clamping should have been done
+       * before here, maybe in Pango, this is a broken band-aid I think
+       */
+      g_assert (index == line_len);
+      
+      _gtk_text_btree_get_iter_at_line (_gtk_text_buffer_get_btree (layout->buffer),
+                                        iter, display->line, 0);
+      gtk_text_iter_forward_to_delimiters (iter);
+    }
+
+  /* FIXME should this be cursor positions? */
   gtk_text_iter_forward_chars (iter, trailing);
 }